# -*- coding: utf-8 -*-
"""
Created on Mon Mar 11 17:36:31 2024

@author: heyuesong
"""


"""
DOM断点

"""

import requests
import pandas as pd
from utils import general

js = general.read_js(r'D:\code\猿人学\第56题.js')


result_list = []
for i in range(1,101):
    print(i)
    headers = {
        "authority": "www.python-spider.com",
        "accept": "application/json, text/javascript, */*; q=0.01",
        "accept-language": "zh-CN,zh;q=0.9",
        "cache-control": "no-cache",
        "content-type": "application/x-www-form-urlencoded; charset=UTF-8",
        "origin": "https://www.python-spider.com",
        "pragma": "no-cache",
        "referer": "https://www.python-spider.com/challenge/56",
        "sec-ch-ua": "\"Chromium\";v=\"122\", \"Not(A:Brand\";v=\"24\", \"Google Chrome\";v=\"122\"",
        "sec-ch-ua-mobile": "?0",
        "sec-ch-ua-platform": "\"Windows\"",
        "sec-fetch-dest": "empty",
        "sec-fetch-mode": "cors",
        "sec-fetch-site": "same-origin",
        "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36",
        "x-requested-with": "XMLHttpRequest"
    }
    cookies = {
        "Hm_lvt_337e99a01a907a08d00bed4a1a52e35d": "1709706135,1709706247",
        "no-alert": "true",
        "_i": "MTcxMDM4MjE3NH5ZV2xrYVc1blgzZHBiakUzTVRBek9ESXhOek0zT0RFPXwwZTU2YWMwMj$0M2Y0ZThmNDMyMjkyMz$zYjI5MjZlZg",
        "_v": "TVRjeE1ETTRNakUzTkg1WlYyeHJZVmMxYmxnelpIQmlha1V6VFZSQmVrOUVTWGhPZWswelQwUkZQWHd3WlRVMllXTXdNaiQwTTJZMFpUaG1ORE15TWpreU16JHpZakk1TWpabFpn",
        "sign": "dvesayfgux",
        "m": "155",
        # "GGæ€\\u009då¯†è¾¾T": "53o2JKKU6vW7qqqmgCw32ZGPmIo3pOAZG.rOmjfQgqIYYz9gOuQ6vk_SIIn5hUqwgYOlC3g01uf8TuucTIS6q2AIUFdiNzVFIY9eiNQzd8KUlClZoYFdeCSa1jyjH6ociVnbTRd0g5Z.m31zBKO.nQ2Na64u1TzG8TpsfQfVdHz9Xlo11ExyVCCtKkncb6vsxqNi7Hb4eNE7fwn1qeS0ldHBh_SdxnfOCGAU67hMauirIVV31ivlKGxQtNoL2qZ9vq",
        "sessionid": "bv637hzboh7a3yn5bx9q7u8mpddaanat",
        "Hm_lpvt_337e99a01a907a08d00bed4a1a52e35d": "1710748132"
    }
    url = "https://www.python-spider.com/api/challenge56"
    data = {
        "page": f"{i}"
    }

    response = requests.post(url, headers=headers, cookies=cookies, data=data,verify=False)
    result = response.json()
    html = js.call('get_sign',result)
    result_list+=html
result_df = pd.DataFrame(result_list)

result_df['value'] = result_df['value'].apply(lambda x:int(x.replace('\r','')))


print(sum(result_df['value']))
